﻿using Miao.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.SceneManagement;
/// <summary>
/// 进行场景切换
/// </summary>
public static class SceneChangeManager
{
    public static event Action OnSceneChangeOneShot;
    public static event Action OnSceneChange;
    #region 名字索引
    public static async Task ChangeScene<T>(string SceneName, bool ClickClose = false) where T : UISceneLoadingPanel, new()
    {
        T uipanel = await UIManager.OpenAsync<T>();
        uipanel.SetChangeScene(SceneName, ClickClose);
        OnSceneChange?.Invoke();
        OnSceneChangeOneShot?.Invoke();
        OnSceneChangeOneShot = null;
    }

    public static async Task ChangeSceneUseLoading(string SceneName, bool ClickClose = false)
    {
        await ChangeScene<Loading>(SceneName, ClickClose);
    }

    public static async Task ChangeSceneUseClickLoading(string SceneName, bool ClickClose = true)
    {
        await ChangeScene<LoadingWait>(SceneName, ClickClose);
    }
    #endregion
    #region ID索引
    public static async Task ChangeScene<T>(int SceneId, bool ClickClose = false) where T : UISceneLoadingPanel, new()
    {
        T uipanel = await UIManager.OpenAsync<T>();
        uipanel.SetChangeScene(SceneId, ClickClose);
        OnSceneChangeOneShot?.Invoke();
        OnSceneChangeOneShot = null;
    }

    public static async Task ChangeSceneUseLoading(int SceneId, bool ClickClose = false)
    {
        await ChangeScene<Loading>(SceneId, ClickClose);
    }

    public static async Task ChangeSceneUseClickLoading(int SceneId, bool ClickClose = true)
    {
        await ChangeScene<LoadingWait>(SceneId, ClickClose);
    }

    #endregion

}

